package com.changgou.goods.dao;

import com.changgou.goods.pojo.Brand;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.PathVariable;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface BrandMapper extends Mapper<Brand> {

	//根据分类名称，查询“品牌名称”和“对应链接”
	@Select("SELECT name,image FROM `tb_brand` WHERE id IN (SELECT brand_id FROM `tb_category_brand` WHERE category_id IN (SELECT category_id FROM `tb_category` WHERE NAME=#{categoryName}))")
	public List<Map> searchBrandInfoByCategory(@Param("categoryName") String categoryName);

	//根据分类名称，查询规格信息
	//注意：sql语句中的name,options最好写成小写，因为代码中习惯将变量小写，导致代码中的name,options与sql语句中的name,options匹配不上，
	//从而报空指针异常
	@Select("SELECT name,options FROM `tb_spec` WHERE template_id IN( SELECT template_id FROM `tb_category` WHERE NAME=#{category})")
	public List<Map> searchSpecInfoByCategory(@Param("category") String category);
}
